import app as robot_script

class Action:

    def __init__(self, framework):
        self.framework = framework
        self.succeed_state = False

    # 设置动作
    def set_action(self, action):
        if action == "on_stand_up":
            self.on_stand_up()
        if action == "on_prostrate":
            self.on_prostrate()
        if action == "on_hello":
            self.on_hello()
        if action == "on_sit":
            self.on_sit()
        if action == "on_dance":
            self.on_dance()
        if action == "on_welcome":
            self.on_welcome()
        if action == "on_turn_over":
            self.on_turn_over()
        if action == "on_step_back":
            self.on_step_back()
        if action == "on_max":
            self.on_max()
        if action == "on_bow":
            self.on_bow()
        if action == "on_come_here":
            self.on_come_here()

    # 起身、站立动作
    def on_stand_up(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_STAND_UP
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_stand_up, result:" + str(self.succeed_state))

    # 趴下、卧倒动作
    def on_prostrate(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_PROSTRATE
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_prostrate, result:" + str(self.succeed_state))

    # 握手、打招呼动作
    def on_hello(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_HI_FIVE
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_hello, result:" + str(self.succeed_state))

    # 坐下、蹲下下动作
    def on_sit(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_SIT
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_sit, result:" + str(self.succeed_state))

    # 跳舞动作
    def on_dance(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_DANCE
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_dance, result:" + str(self.succeed_state))

    # 欢迎、拜年、恭喜动作
    def on_welcome(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_WELCOME
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_welcome, result:" + str(self.succeed_state))

    # 翻身动作
    def on_turn_over(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_TURN_OVER
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_turn_over, result:" + str(self.succeed_state))

    # 后踏步动作
    def on_step_back(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_STEP_BACK
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_step_back, result:" + str(self.succeed_state))

    # 转身 转圈动作
    def on_turn_around(self, para=0.0):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_TURN_AROUND
            request.order.para = para
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_turn_around, result:" + str(self.succeed_state))

    # 集合动作
    def on_max(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_MAX
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_max, result:" + str(self.succeed_state))

    # 鞠躬低头动作（未开放动作？）
    def on_bow(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_BOW
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_bow, result:" + str(self.succeed_state))

    # 过来、到这里来动作（未开放动作？）
    def on_come_here(self):
        if self.framework.cyberdog_subscribe is not None:
            request = self.framework.cyberdog_pb2.ExtMonOrder_Request()
            request.order.id = self.framework.cyberdog_pb2.MonOrder.MONO_ORDER_COME_HERE
            request.order.para = 0
            request.timeout = 0
            response = self.framework.cyberdog_subscribe.setExtmonOrder(request)
            for resp in response:
                self.succeed_state = resp.succeed
                self.framework.framework.common.socket.log("Action on_come_here, result:" + str(self.succeed_state))
